<?php
/**
 * @Author: rocky
 * Date: 2019/9/25
 * Time: 16:31
 */


namespace app\shop\model;

use app\shop\model\ShopMemberAddress;
use app\common\model\PcasArea;

use app\common\model\BaseModel;
class ShopMemberAddress extends BaseModel
{
    protected $append = ['full_address'];
    protected function getFullAddressAttr($val,$data){
        return $data['province'].$data['city'].$data['area'].$data['address'].$data['detailed_address'];
    }
    
    
    //递归查询最低级地址父级id
    public function getParentIds ($address_code,$depth = 0){
        // 定义一个空数组，用于存储父级 ID
        $parentIds = [];
        
        $addIdarr = PcasArea::where('id',$address_code)->find();
        $parentIds[] = $addIdarr;
        // halt($addId4);
        
        // 查询地址父级id
        $parentId = PcasArea::where('id',$address_code)->value('parent_id');
        
        if($parentId && $depth<3){
            $parentIds = array_merge($parentIds,ShopMemberAddress::getParentIds($parentId,$depth+1));
        }
        return $parentIds;
    }
}